package com.maimao.cart.client.factory;

import com.maimao.cart.client.CouponClient;
import com.maimao.core.enums.RespCode;
import com.maimao.core.model.resp.Result;
import com.maimao.model.info.MgCoupon;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class CouponFallBackFactory implements FallbackFactory<CouponClient> {

    @Override
    public CouponClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new CouponClient() {


            @Override
            public Result<List<MgCoupon>> queryCouponsByShop(Long shopId) {
                log.error("调用[CouponClient-queryCouponsByShop({}})]出错 :{}", shopId, errorMsg);
                return Result.fail(RespCode.FAIL, errorMsg);
            }


        };
    }
}
